package com.example.smartcity_40.lawyer.apter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.smartcity_40.R;
import com.example.smartcity_40.lawyer.LawyerdetailsActivity;
import com.example.smartcity_40.lawyer.LawyerexpertiseActivity;
import com.example.smartcity_40.lawyer.bean.LegalexpertiseBean;
import com.example.smartcity_40.tool.Tool;

import java.util.List;

public class LawyerBannerApter extends  RecyclerView.Adapter<LawyerBannerApter.Myhot> {

    private Context context;
    private List<LegalexpertiseBean.RowsBean> list;

    public LawyerBannerApter(Context context) {
        this.context = context;
    }

    public void setDate(List<LegalexpertiseBean.RowsBean> list){
        this.list = list;
    }
    @NonNull
    @Override
    public LawyerBannerApter.Myhot onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.l_item_service, null);
        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(270, 200);
        inflate.setLayoutParams(layoutParams);
        return new LawyerBannerApter.Myhot(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull LawyerBannerApter.Myhot holder, int position) {
        try {
            String imgUrl = list.get(position).getImgUrl();
            if(!TextUtils.isEmpty(imgUrl)){
                Glide.with(context).load(Tool.url+imgUrl).into(holder.imgurl);
            }

            String serviceName = list.get(position).getName();
            if(!TextUtils.isEmpty(serviceName)){
                holder.serviceName.setText(serviceName);
            }


            holder.relayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, LawyerexpertiseActivity.class);
                    context.startActivity(intent);
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    class Myhot extends RecyclerView.ViewHolder{

        private final TextView serviceName;
        private final ImageView imgurl;
        private final RelativeLayout relayout;

        public Myhot(@NonNull View itemView) {
            super(itemView);
            imgurl = itemView.findViewById(R.id.imgurl);
            serviceName = itemView.findViewById(R.id.serviceName);
            relayout = itemView.findViewById(R.id.relayout);
        }
    }
}

